<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用构造器创建 JavaScript 对象</title>
</head>

<body>
    <h1>JavaScript 对象构造器</h1>
    <p id="demo"></p>
    <script>
        // Person 对象的构造器函数
        function Person(first, last, age, eye) {
            this.firstName = first;
            this.lastName = last;
            this.age = age;
            this.eyeColor = eye;
        }

        // 创建 Person 对象
        var myFriend = new Person("gill", "Gates", 6, "blue");

        // 显示年龄
        document.getElementById("demo").innerHTML =
            "My friend is " + myFriend.age + ".";
    </script>
</body>

</html>